{include file="public/head"/}
<style>
    .layui-form-item .layui-input-company {
        width: auto;
        padding-right: 10px;
        line-height: 38px;
    }
</style>

<body>
    <div class="layuimini-container">
        <div class="layuimini-main">

            <div class="layui-form layuimini-form">
                <div class="layui-form-item">
                    <label class="layui-form-label required">网站名称</label>
                    <div class="layui-input-block">
                        <input type="text" name="name" value="{$info.name}" lay-verify="required" lay-reqtext="网站名称不能为空"
                            placeholder="请输入网站名称" value="layuimini" class="layui-input">
                        <tip>填写自己部署网站的名称。</tip>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">网站描述</label>
                    <div class="layui-input-block">
                        <input type="text" name="desc" value="{$info.desc}"
                            placeholder="请输入网站描述" value="layuimini" class="layui-input">
                        <tip>填写自己部署网站的描述。</tip>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label required">网站地址</label>
                    <div class="layui-input-block">
                        <input type="text" name="address" value="{$info.address}" lay-verify="required" lay-reqtext="网站名称不能为空"
                            placeholder="请输入网站服务地址" value="layuimini" class="layui-input">
                        <tip>填写自己网站服务地址。</tip>
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label required">标志图</label>
                    <div class="layui-input-inline">
                        <input type="hidden" name="image" id="img2" value="{$info.image}" lay-verify="required" lay-reqtext="图片不可为空">
                        <button type="button" class="layui-btn layui-btn-sm layui-btn-normal" id="img">上传图片</button>
                        <div class="layui-upload-list">
                            <img class="layui-upload-img" id="img1" src="{$info.image}" style="width:300px;">
                        </div>
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label required">版权信息</label>
                    <div class="layui-input-block">
                        <input type="text" name="copyright" value="{$info.copyright}" lay-verify="required" lay-reqtext="版权信息不能为空"
                            placeholder="版权信息" value="layuimini" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn layui-btn-normal" lay-submit lay-filter="setting">确认保存</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script>
        layui.use(['form','upload'], function () {
            var form = layui.form
                , layer = layui.layer
                , upload = layui.upload
                ,$ = layui.$;

           //普通图片上传
           var uploadInst = upload.render({
                elem: '#img',
                url: "{:url('upFiles/upload')}",
                data: {width:250,height:250},
                accept: 'images', //普通文件
                exts: 'jpg|png|gif|jpeg', //只允许上传压缩文件
                before: function () {
                //开始加载效果
                    layui.use('layer', function () {
                        layui.layer.load();
                        $(".layui-layer-shade").css('background', '#000000')
                        $(".layui-layer-shade").css('opacity', '0.2')
                        $(".layui-layer-shade").click(function (event) {
                            event.stopPropagation();
                        })
                    })
                },
                done: function(res){
                    //上传成功结束加载效果
                    layui.use('layer', function () {
                        layui.layer.closeAll();
                        setTimeout(function () {
                            layui.layer.closeAll();
                        }, 2000);
                    });
                    if(res.code === 1){
                        $('#img1').attr('src', res.url);
                        $('#img2').val(res.url);
                        layer.msg(res.info, {icon: 1});
                    } else {
                        layer.msg(res.msg, {icon: 5});
                    }
                },
                error: function(){
                    //上传成功结束加载效果
                    layui.use('layer', function () {
                        layui.layer.closeAll();
                        setTimeout(function () {
                            layui.layer.closeAll();
                        }, 2000);
                    });
                    return layer.msg('上传失败',{icon:2});
                }
            });


            //监听提交
            form.on('submit(setting)', function (data) {
                delete data.field.file; // 删除文件上传的file
                $.post('', data.field, function (res) {
                    if (res.code > 0) {
                        layer.msg(res.msg, { time: 1800, icon: 1 }, function () {
                            location.reload();
                        });
                    } else {
                        layer.msg(res.msg, { time: 1800, icon: 2 });
                    }
                });
                return false;
            });

        });
    </script>
    {include file="public/footer"/}